//
//  DiscountCell.m
//  meituan
//
//  Created by jinzelu on 15/7/2.
//  Copyright (c) 2015年 jinzelu. All rights reserved.
//

#import "DiscountCellH.h"

@interface DiscountCellH ()
{
    NSMutableArray *_array;
}

@end

@implementation DiscountCellH

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _array = [[NSMutableArray alloc] init];
        
        int height = ImageH;
        for (int i = 0; i < 4; i++) {
            //背景
            UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(i*SCREEN_WIDTH/2, 0, SCREEN_WIDTH/2, height)];
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH/2-ViewG)/2, (height-ViewG)/2, ViewG, ViewG)];
            if (i<2) {
                backView.frame = CGRectMake(i*SCREEN_WIDTH/2, 0, SCREEN_WIDTH/2, height);
            }else{
                backView.frame = CGRectMake((i-2)*SCREEN_WIDTH/2, height, SCREEN_WIDTH/2,height);
            }
            if (i%2==0) {
                imageView.frame = CGRectMake((SCREEN_WIDTH/5*2-ViewG)/2, (height-ViewG)/2, ViewG, ViewG);

            }else{
                imageView.frame = CGRectMake((SCREEN_WIDTH/3-ViewG)/2, (height-ViewG)/2, ViewG, ViewG);

            }
            backView.tag = 100+i;
            [self.contentView addSubview:backView];
            //点击事件
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(OnTapBackView:)];
            [backView addGestureRecognizer:tap];
            
            //图
            imageView.tag = 240+i;
            [imageView setImage:[UIImage imageNamed:@"bg_customReview_image_default"]];
            imageView.layer.masksToBounds = YES;
            imageView.layer.cornerRadius = ViewG/2;
            [backView addSubview:imageView];

            UILabel  *titleLabel = [UILabel new];
            [backView addSubview:titleLabel];
            titleLabel.font = [UIFont systemFontOfSize:15];
            titleLabel.text = [NSString stringWithFormat:@"暑期"];
            titleLabel.tag = 200+i;
            [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(imageView.mas_centerY);
                make.left.equalTo(imageView.right).with.offset(15);
                make.height.mas_equalTo(@30);
                make.width.mas_equalTo(@60);
            }];
            
            UIView *lineView = [UIView new];
            lineView.backgroundColor = RGB(220, 220, 223);
            [self.contentView addSubview:lineView];
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.contentView.mas_centerY);
                make.left.equalTo(self.contentView).with.offset(20);
                make.right.equalTo(self.contentView).with.offset(-20);
                make.height.mas_equalTo(@1);
            }];

        }
    }
    return self;
}

-(void)setDiscountArray:(NSMutableArray *)discountArray{
    _discountArray = discountArray;
    
    for (int j = 0; j < 4; ++j) {
        UILabel *titleLabel = (UILabel *)[self viewWithTag:j+200];
        UIImageView *imageView = (UIImageView *)[self viewWithTag:j+240];
        titleLabel.font = [UIFont systemFontOfSize:14];
        NSDictionary *dict = discountArray[j];
        titleLabel.text = dict[@"title"];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",dict[@"image"]]];
    }
}

-(void)OnTapBackView:(UITapGestureRecognizer *)sender{

    NSInteger index = sender.view.tag-100;
    if ([_delegate respondsToSelector:@selector(didSelectDiscountIndex:)]) {
        [_delegate didSelectDiscountIndex:index];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


- (void)awakeFromNib {
    // Initialization code
}
@end
